package com.atguigu.filter;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebFilter("/user/*")
public class HostFilter extends HttpFilter {
    //todo 如果是非本机访问，则跳转到非法访问页面 ^_^
    @Override
    protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
        String host = request.getRemoteAddr();
        if (host.equals("127.0.0.1") || host.equals("192.168.13.235"))
            chain.doFilter(request, response);
        else response.sendRedirect("/illegalAccess.html");
    }
}
